package cn.bdqn.servlet;

import cn.bdqn.entity.Students;
import cn.bdqn.service.StudentsService;
import cn.bdqn.service.impl.StudentsServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author: DELL
 * @Since: 2024/9/19 19:33
 * @Description:
 */
@WebServlet("/StudentsServlet")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        StudentsService studentsService=new StudentsServiceImpl();
        List<Students> studentsList =studentsService.getAll();
        String student= JSON.toJSONString(studentsList);
        PrintWriter out=resp.getWriter();
        out.print(student);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
